package com.ahsjdy.st.stbomanagerweb.controller;

import com.ahsjdy.st.stservice.service.impl.AdminCommonServiceImpl;
import com.ahsjdy.st.stservice.service.impl.MerchantServiceImpl;
import com.ahsjdy.st.stservice.service.impl.RiderServiceImpl;
import com.ahsjdy.stcommon.dto.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author xuetao wang
 * @Date 2019/12/29
 */
@RestController
public class AdminController extends BaseController {

    @Autowired
    private AdminCommonServiceImpl adminCommonService;

    @Autowired
    private MerchantServiceImpl merchantService;

    @Autowired
    private RiderServiceImpl riderService;

    @RequestMapping("/admin/addArea")
    public ResponseDTO addArea(String areaName, String lat, String lon) {
        adminCommonService.addArea(areaName, lat, lon);
        return ResponseDTO.success();
    }

    @RequestMapping("/admin/listArea")
    public ResponseDTO listArea(String areaName) {
        return ResponseDTO.success(adminCommonService.listArea(areaName));
    }

    @RequestMapping("/admin/yunyingArea")
    public ResponseDTO yunyingArea(int areaId) {
        adminCommonService.changeStatusArea(areaId, 1);
        return ResponseDTO.success();
    }

    @RequestMapping("/admin/jinyongArea")
    public ResponseDTO jinyongArea(int areaId) {
        adminCommonService.changeStatusArea(areaId, 2);
        return ResponseDTO.success();
    }

    @RequestMapping("/admin/queryArea")
    public ResponseDTO queryArea(int areaId) {
        return ResponseDTO.success(adminCommonService.queryArea(areaId));
    }

    @RequestMapping("/admin/modifyArea")
    public ResponseDTO modifyArea(int areaId, String areaName, String lat, String lon) {
        adminCommonService.modifyArea(areaId, areaName, lat, lon);
        return ResponseDTO.success();
    }

    //审批商家申请
    @RequestMapping("/admin/approvalMerchant")
    public ResponseDTO approvalMerchant(int merchantId, int status) {
        merchantService.changeMerchantStatus(merchantId, status);
        return ResponseDTO.success();
    }

    //商家列表
    @RequestMapping("/admin/listMerchant")
    public ResponseDTO listMerchant(String merchantName, Integer areaId,
                                    Integer status, @RequestParam(required = false, defaultValue = "1") Integer pageNumber,
                                    @RequestParam(required = false, defaultValue = "20")Integer pageSize) {
        return ResponseDTO.success(merchantService.listMerchant(merchantName, areaId, status, pageNumber, pageSize));
    }

    @RequestMapping("/admin/changeMerchant")
    public ResponseDTO changeMerchant(int merchantId, int status) {
        merchantService.changeMerchantStatus(merchantId, status);
        return ResponseDTO.success();
    }


    @RequestMapping("/admin/approvalRider")
    public ResponseDTO approvalRider(int riderId, int status) {
        riderService.changeStatus(riderId, status);
        return ResponseDTO.success();
    }

    //骑手列表
    @RequestMapping("/admin/listRider")
    public ResponseDTO listRider(String realName,  String phone, int status,
                                 @RequestParam(required = false, defaultValue = "1") Integer pageNumber,
                                 @RequestParam(required = false, defaultValue = "20")Integer pageSize) {
        return ResponseDTO.success(riderService.listRiders(realName, phone, status, pageNumber, pageSize));
    }

}
